<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>6.270 - JoyOS: kern/lock.h File Reference</title>
	<link href="main.css" media="screen" rel="Stylesheet" type="text/css"/>
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>  
<body>
	<div id="header">
		<div id="headerb">
		<div id="headtext">
			<span class="titletext">AUTONOMOUS ROBOT DESIGN COMPETITION</span>
			6.270
		</div>
		<div class="mainmenu">
			<a href="http://web.mit.edu/6.270/www">Home</a>
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/about/">About</a> 
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/sponsors/">Sponsors</a>
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/contests/">Past Contests</a> 
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/contestants/">Contestant Information</a>
		</div>
	</div>
	</div>

<div class="maincontent">
<!-- Generated by Doxygen 1.5.1 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    <li><a href="globals.html"><span>Globals</span></a></li>
  </ul></div>
<h1>kern/lock.h File Reference</h1>Locks. <a href="#_details">More...</a>
<p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="d7eebd1d1791b31f512f270d9a611cd2"></a><!-- doxytag: member="lock.h::LOCK_MAX_ACQUIRES" ref="d7eebd1d1791b31f512f270d9a611cd2" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="lock_8h.html#d7eebd1d1791b31f512f270d9a611cd2">LOCK_MAX_ACQUIRES</a>&nbsp;&nbsp;&nbsp;255</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Maximum number of recursive acquires. <br></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="lock_8h.html#e68b839d3741f86e5ad84c319138578e">init_lock</a> (struct lock *k, const char *name)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="lock_8h.html#a06dd7979701afdae569eee601af701d">acquire</a> (struct lock *k)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="lock_8h.html#e8ea3e69eb91c70496c23dab44661f2d">is_held</a> (struct lock *k)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="lock_8h.html#66c271140ac6973da522dd0d89f0c3b6">release</a> (struct lock *k)</td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
JoyOS includes a locking mechanism, useful when writing multi-threaded code. Locks allow sections of code to be protected, requiring a thread to acquire the lock before continuing. This allows multiple threads to to share a single resource (such as a variable, or a sensor). All of the Happyboard hardware drivers are locked to ensure thread-safe operation <hr><h2>Function Documentation</h2>
<a class="anchor" name="a06dd7979701afdae569eee601af701d"></a><!-- doxytag: member="lock.h::acquire" ref="a06dd7979701afdae569eee601af701d" args="(struct lock *k)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void acquire           </td>
          <td>(</td>
          <td class="paramtype">struct lock *&nbsp;</td>
          <td class="paramname"> <em>k</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Acquire the lock 'k'. If another thread holds the lock yield until it is available, then take it. A thread can recursively acquire the same lock multiple times, but it must release once for every acquire.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>k</em>&nbsp;</td><td>Lock to acquire. Must be non-null. </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="e68b839d3741f86e5ad84c319138578e"></a><!-- doxytag: member="lock.h::init_lock" ref="e68b839d3741f86e5ad84c319138578e" args="(struct lock *k, const char *name)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void init_lock           </td>
          <td>(</td>
          <td class="paramtype">struct lock *&nbsp;</td>
          <td class="paramname"> <em>k</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&nbsp;</td>
          <td class="paramname"> <em>name</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Initialize the lock 'k'. This routine must be called before lock 'k' is used.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>k</em>&nbsp;</td><td>Lock to initialize, must be non-null. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>name</em>&nbsp;</td><td>Debugging name for lock. </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="e8ea3e69eb91c70496c23dab44661f2d"></a><!-- doxytag: member="lock.h::is_held" ref="e8ea3e69eb91c70496c23dab44661f2d" args="(struct lock *k)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int is_held           </td>
          <td>(</td>
          <td class="paramtype">struct lock *&nbsp;</td>
          <td class="paramname"> <em>k</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Checks to see if lock 'k' is held by the current thread.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>k</em>&nbsp;</td><td>Lock to check. Must be non-null. </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Non-zero if lock is held by current thread, zero otherwise. </dd></dl>

</div>
</div><p>
<a class="anchor" name="66c271140ac6973da522dd0d89f0c3b6"></a><!-- doxytag: member="lock.h::release" ref="66c271140ac6973da522dd0d89f0c3b6" args="(struct lock *k)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void release           </td>
          <td>(</td>
          <td class="paramtype">struct lock *&nbsp;</td>
          <td class="paramname"> <em>k</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Release the lock 'k'.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>k</em>&nbsp;</td><td>Lock to release. Must be non-null. </td></tr>
  </table>
</dl>

</div>
</div><p>
</div>
<div class="maincontent">
	<div class="footer centre">
		<hr>
		Generated on Tue Jan 29 23:17:08 2008 by&nbsp;<a href="http://www.doxygen.org/index.html">Doxygen</a> 1.5.1<br/>
		6.270 Staff, 2008 | 
		<a href="mailto:6.270-organizers@mit.edu">Contact Us</a> | 
		<a href="http://web.mit.edu">MIT</a>
	</div>
</div>
</body>
</html>
